package org.martyn.danbodroid.gui.activitys;

import java.io.IOException;

import org.martyn.danbodroid.DanboDroid;
import org.martyn.danbodroid.R;
import org.martyn.danbooru.error.DanbooruException;
import org.martyn.danbooru.types.Post;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class PostViewActvity extends Activity
{
	public static final String POST_VIEW_ACTIVITY_DATA_POST_KEY = "KEY_PREF_POST";

	private Post post;

	private ImageView postPictureView;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.post_view);

		intentExtrasFilter();

		initLayout();

	}

	private void intentExtrasFilter()
	{
		post = (Post) this.getIntent().getSerializableExtra(
				POST_VIEW_ACTIVITY_DATA_POST_KEY);
	}

	private void initLayout()
	{
		this.postPictureView = (ImageView) this
				.findViewById(R.id.postPictureView);

		DanboDroid danboDroid = (DanboDroid) this.getApplication();

		 try
		 {
		 postPictureView.setImageBitmap(danboDroid.getDanbooru().picture(post
		 .getFileUrl()));
		 }
		 catch (DanbooruException e)
		 {
		 e.printStackTrace();
		 }
		 catch (IOException e)
		 {
		 e.printStackTrace();
		 }

	}
}
